<%@page import="java.util.ArrayList"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@ page import="com.google.appengine.api.datastore.Query"%>
<%@ page import="com.google.appengine.api.datastore.Entity"%>
<%@ page import="com.google.appengine.api.datastore.FetchOptions"%>
<%@ page import="com.google.appengine.api.datastore.Key"%>
<%@ page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@ page import="edu.dhbw.mannheim.Admin"%>
<%@ page import="java.util.Date"%>
<%
	List<Entity> admins = Admin.getListOfAdminEntities();
%>
<div class="round">
	<%
		if (admins.isEmpty()) {
	%>
	<p>Strange... There are no admins. You should not see this :o</p>
	<%
		}
	%>
	<p>The following people can write new blog posts:</p>
	<table id="adminList">
		<tr>
			<th>username</th>
			<th>is able to post?</th>
			<th>is admin?</th>
			<th>date added</th>
			<th>action</th>
		</tr>
		<%
			for (Entity admin : admins) {
				try {
					String username = admin.getProperty("user").toString();
					int canPost = Integer.parseInt(admin.getProperty("post").toString());
					int isAdmin = Integer.parseInt(admin.getProperty("admin").toString());
					Date date = (Date) admin.getProperty("date");
				
		%><tr>
			<%= Admin.createNewAdminRow(Admin.findUser(username), canPost, isAdmin, date) %>
		</tr>
		<%
				} catch(Exception e) {
					System.out.println("Error getting all properties from datastore");
				}
			}
		%>
		<tr>
			<td><input type="text" id="username" size="35" onkeydown="if (event.keyCode == 13) newAdmin()" /></td>
			<td><input type="checkbox" id="canPost" checked /></td>
			<td><input type="checkbox" id="isAdmin" /></td>
			<td></td>
			<td><b><a  href='#' onClick='javascript:newAdmin()'>+</a></b></td>
		</tr>
	</table>
</div>